package main

import (
	"fmt"
	"sort"
	"strconv"
)

func main() {
	nums := []int{0,0,0,0}
	arr := fourSum(nums, 1)
	fmt.Println(arr)
}
func fourSum(nums []int, target int) [][]int {

	sort.Ints(nums)
	var result [][]int
	m := make(map[string]int)

	for i := 0; i < len(nums); i++ {
		for j := i + 1; j < len(nums); j++ {
			left, right := j+1, len(nums)-1

			for left < right {
				sum := nums[i] + nums[j] + nums[left] + nums[right]
				if sum == target {
					arr := []int{nums[i], nums[j], nums[left], nums[right]}
					left++
					right--
					sort.Ints(arr)
					str := ""
					for _, v := range arr {
						str += strconv.Itoa(v)
					}

					_, ok := m[str]
					if ok {
						continue
					}
					m[str] = target
					result = append(result, arr)

				} else if sum > target {
					right--
				} else if sum < target {
					left++
				}
			}
		}
	}

	return result
}
func dup(a []int) []int {
	b := make([]int, len(a))
	copy(b,a)
	return b
}